/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.hogent.designpatterns.billenkar.commands;

import be.hogent.designpatterns.billenkar.BillenkarVerzameling;
import java.util.Scanner;

/**
 *
 * @author Jeroen
 */
public class HoofdMenuCommand implements Command {
    private BillenkarVerzameling billenkarVerzameling;
    private Command[] commandos;
    private Scanner in = new Scanner(System.in);

    public HoofdMenuCommand(BillenkarVerzameling billenkarVerzameling) {
        this.billenkarVerzameling = billenkarVerzameling;
        commandos = new Command[3];
        commandos[0] = new VoegBillenkarToeCommand(billenkarVerzameling);
        commandos[1] = new KiesBillenkarCommand(billenkarVerzameling);
        commandos[2] = new LeegCommand();
    }

    public void execute() {
        int keuze = doeMenu();
        while(keuze == -1) {
            System.out.println("ONGELDIGE KEUZE!");
            keuze = doeMenu();
        }
        commandos[keuze-1].execute();
    }

    private int doeMenu() {
         System.out.println("****************************************************");
         System.out.println("             VELOVERHURING BILLENKAR");
         System.out.println("****************************************************");
         System.out.println("");
         System.out.println("");
         System.out.println("--------------------HOOFDMENU-----------------------");
         System.out.println("");
         System.out.println("1. Voeg Billenkar toe.");
         System.out.println("2. Kies Billenkar.");
         System.out.println("3. Afsluiten");
         System.out.println("");
         System.out.println("Maak uw keuze: ");
         int keuze;
         String inv = in.nextLine();
         try {
             keuze = Integer.parseInt(inv);
             if(keuze<1 || keuze>3) {
                 throw new NumberFormatException();
             }
         } catch (NumberFormatException e) {
             keuze = -1;
         }
         return keuze;
    }



}
